<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
		<title></title>
    <script type="text/javascript" src="../script/config.js"></script>
		<style>
    *{
      margin:0;
      padding:0;
    }
		body{
			/*width:100%;
			height:100%;*/
			background-color:white;
		}
    header{ background-color: #f16c3c; line-height: 42px; height: 42px; position: relative;z-index:999;padding-top:22px;}
    header b{ width: 42px; height: 100%; display: inline-block; position: relative; z-index: 1; background: url() no-repeat center; background-size: 70% auto;  }
    header b.ic-back{ background-image: url(../image/back.png);background-size:25px 25px;}
    /*header b.ic-check{ background-image: url(../image/ic-check.png); float: right; }*/
    header .title{ position: absolute; left: 0; bottom: 0; right: 0;  text-align: center; font-size: 18px;color:white;}

			.p_code,.p_sign{
				color:#f16c3c;
				margin:0 auto;
				width:100%;
				height:40px;
				text-align:center;
        margin-top:10px;
			}
			.sign{
				background:rgb(138,171,202);
				width:150px;
				height:150px;
				margin:20px auto;
				text-align:center;
				line-height:150px;
        border-radius:20px;
        font-size:25px;
        color:white;
			}
      .code{
        width:200px;
				height:200px;
				margin:20px auto;
      }
		</style>
	</head>
  <script type="text/javascript" src="../script/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../script/jquery.qrcode.js"></script>
<script type="text/javascript" src="../script/qrcode.js"></script>
<script type="text/javascript" src="../script/api.js"></script>
	<body>
    <div id="wrap" class="flex-wrap flex-vertical" >
        <header class="border-b" >
            <b tapmode="hover" onclick="api.closeWin();" class="ic-back"></b>
            <div class="title">选择交付方式</div>
        </header>
		<div class="code"></div>
    <div class="p_code">(物流管理系统前台扫码接单)</div>
		<div class="sign">签字交付</div>
    <div class="p_sign">(未安装管理系统的物流公司收货)</div>
  </div>
	</body>
  <script type="text/javascript">
	var aaa;
  apiready = function(){
		api.closeWin({
				name: 'warn'
		});
    var scheduling_id=api.pageParam.scheduling_id;
		$api.get(url+'app.php/company_customer?scheduling_id='+scheduling_id+'',function(ret){
				 if(ret.result==0){
					 aaa=1;
				 }
			 },'json');
		check_company(scheduling_id);
		var is_wuliu=api.pageParam.is_wuliu;
		// alert(is_wuliu);
//   alert(id);
    $(".code").qrcode({
     render: "table",
     width: 200,
     height:200,
     text:scheduling_id
  });
    api.addEventListener({
                          name:'viewappear'
                      }, function(ret, err){
                         api.setScreenOrientation({
                          orientation: 'auto_portrait'
                      });
                      });
    // $api.addEvt($api.dom('.code'), 'click',function(){
    //   // api.openWin({
    //   //     name: 'qrcode',
    //   //     url: './qrcode.html',
    //   //     pageParam: {
    //   //           scheduling_id:api.pageParam.scheduling_id
    //   //             }
    //   // });
    // });
    $api.addEvt($api.dom('.sign'), 'click',function(){
			if(aaa==1){
				api.toast({
					 msg: '商户编号已确定，请扫码接单',
					 duration: 2000,
					location: 'middle'
				});

			}else{
				api.openWin({
	          name: 'signmain',
	          url: './signmain.html',
						slidBackEnabled:false,
	          pageParam: {
	                scheduling_id:api.pageParam.scheduling_id,
									is_wuliu:api.pageParam.is_wuliu,
	                  }
	      });
			}

    });

		var user = $api.getStorage('user');
		var lorryid=user.lorryid;
		setInterval("check_scheduling("+lorryid+",'"+scheduling_id+"')",3000);
  }

function check_scheduling(lorry_id,scheduling_id){
	$api.get(url+'app.php/check_scheduling?lorry_id='+lorry_id+'&scheduling_id='+scheduling_id+'',function(ret){
			 if(ret.result==0){
				 api.closeToWin({
	           name: 'main'
          });
			 }
		 },'json');
}


function check_company(scheduling_id){
	$api.get(url+'app.php/company_customer?scheduling_id='+scheduling_id+'',function(ret){
			 if(ret.result==0){
         aaa=1;
			 }
		 },'json');
}
  </script>
</html>
